package cn.lg.soar.core.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class ThreadPoolConfig {

    @Bean("pool1C10P100Q180S")
    public ExecutorService yourTaskPool() {
        int corePoolSize = 1;
        int maxPoolSize = 10;
        int queueCapacity = 100;
        long keepAliveSeconds = 180;

        ThreadPoolExecutor executor = new ThreadPoolExecutor(
            corePoolSize,
            maxPoolSize,
            keepAliveSeconds, TimeUnit.SECONDS,
            new LinkedBlockingQueue<>(queueCapacity),
            new CustomizableThreadFactory("pool1C10P100Q180S"),
            new ThreadPoolExecutor.CallerRunsPolicy()
        );

        return executor;
    }
    
}